package com.bell.atensettings.settingDetails;

import com.android.internal.os.storage.ExternalStorageFormatter;
import com.bell.atensettings.R;
import com.bell.atensettings.widgets.RecoveryAlertDialog;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;

public class RecoverySetting extends Activity implements OnClickListener
{
    private ImageButton mRecoryBtn;
    
    private Handler mHandler = new Handler()
    {
        @Override
        public void handleMessage(Message message)
        {
            switch (message.what)
            {
                case 1:
                    Intent intent = new Intent("com.android.internal.os.storage.FORMAT_AND_FACTORY_RESET");
                    
                    intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
                    startService(intent);
                    break;

                default:
                    break;
            }
        }
        
    };

    @Override
    protected void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);
        setContentView(R.layout.recovery_setting);

        mRecoryBtn = (ImageButton) findViewById(R.id.recovery);
        mRecoryBtn.setOnClickListener(this);
    }

    @Override
    public void onBackPressed()
    {
        super.onBackPressed();

        overridePendingTransition(R.anim.start, R.anim.push_left_out);
    }

    @Override
    public void onClick(View view)
    {
        RecoveryAlertDialog.Builder recoveryBuilder = new RecoveryAlertDialog.Builder(this);

        recoveryBuilder.setTitle(getResources().getString(R.string.recovey_dialog))
                .setPositiveButton(new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int code)
                    {
                        mHandler.sendEmptyMessage(1);
                        dialog.dismiss();
                    }
                }).setNegativeButton(new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int code)
                    {
                        dialog.dismiss();
                    }
                });
        
        recoveryBuilder.create().show();
    }

}
